//Purpose: This is a JavaScript
//that validates "name", "zipcode",
//and "email"
//Name -- must have at least 5 characters
//Zip -- must be 5 digits long and only digits
//email -- must have "@" and be at least 5 characters long
//			the "@" and last "." symbols are test for proper form.
//			this allows the use of "." in the email name (like in Google)
//			however, it ensures the last one following the @ symbol is valid

document.onsubmit = function() {
//assign variable values
var fullname = document.getElementById("fullname").value;
var zipcode = document.getElementById("zipcode").value;
var email = document.getElementById("email").value;
var atLocation = email.indexOf("@");
var dotLocation = email.lastIndexOf(".");
var notNumber = isNaN(zipcode);
	//Test name field
	if(fullname=="" || fullname==null || fullname.length < 5){
	alert("You must enter a name and it must be at least 5 characters. You only entered: "+fullname.length +" characters.");
	document.forms['inputForm'].elements['fullname'].focus();
	return false;
	}
	//Test Zipcode field
	if(zipcode=="" || zipcode==null || zipcode.length != 5 || notNumber==true){
	alert("You must enter a valide 5-digit numeric zip code.");
	document.forms['inputForm'].elements['zipcode'].focus();
	return false;
	}
	//Test email field
	//atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length
	if(email=="" || email==null || email.length < 5 || atLocation < 1 || dotLocation < atLocation+2 || dotLocation+2 >= email.length){
	alert("You must enter a valid email address.");
	document.forms['inputForm'].elements['email'].focus();
	return false;
	}
};